﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OPMS_V1.BOL;
using System.Security.Cryptography;
using System.IO;
using System.Text;

namespace OPMS_V1.Public
{
    public partial class PlaceAd : System.Web.UI.Page
    {
        Register objRegBOL = new Register();
        Crypto crypt = new Crypto();

        protected void Page_Load(object sender, EventArgs e)
        {
            lblLoginError.Visible = false;
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //Registration details parameters
            Boolean successful = false;
            string accountName = txtAccountName.Text;
            string password = crypt.Encrypt(txtPassword.Text);
            string lastLogin = System.Convert.ToString(DateTime.Now);

            if (accountName == "" || txtPassword.Text == "")
            {
                lblLoginError.Visible = true;
            }
            else
            {
                //Trying to validate the user with the Username and encrypted Password stored on to the database
                int response = objRegBOL.ValidateUser(accountName, password);

                if (response == 0)
                {
                    successful = true;
                    Session["user"] = accountName;
                }
                else
                {
                    successful = false;
                    lblLoginError.Visible = true;
                }

                if (successful == true)
                {
                    Response.Redirect("~//ManageAds//PropertyList.aspx");
                }
            }
        }

        protected void lnkForgot_Click(object sender, EventArgs e)
        {
            Response.Redirect("~\\AccessControls\\ForgottenPassword.aspx");
        }

        protected void btnSell_Click(object sender, EventArgs e)
        {

        }

        protected void btnSell_Click1(object sender, EventArgs e)
        {
            Session["propertyAdType"] = "ForSell";
            Response.Redirect("~\\Public\\StartAd.aspx?Mode=" + Session["propertyAdType"].ToString());
        }

        protected void btnRent_Click(object sender, EventArgs e)
        {
            Session["propertyAdType"] = "ForRent";
            Response.Redirect("~\\Public\\StartAd.aspx?Mode=" + Session["propertyAdType"].ToString());
        }

        protected void btnplaceShare_Click(object sender, EventArgs e)
        {
            Session["propertyAdType"] = "ForShare";
            Response.Redirect("~\\Public\\StartAd.aspx?Mode=" + Session["propertyAdType"].ToString());
        }
    }
}
